home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _E230192A474544D8A054E8E777AA025B < prev    next >
Text File  |  2005-02-17  |  2KB  |  105 lines

  1. //flag wavery in the wind shader
  2. //2 directional lights applied
  3.  
  4. //Luke Lenhart
  5. //(C)2004-2005 Digipen Institute of Technology
  6.  
  7. //world,view,projection transforms
  8. float4x4 matWorldViewProj;
  9. float4x4 matWorld;
  10.  
  11. //2 directional lights
  12. float4 l1Direction;
  13. float4 l1Color;
  14.  
  15. float4 l2Direction;
  16. float4 l2Color;
  17.  
  18. //ambient light
  19. float4 lAmbient;
  20.  
  21. //opacity of flag
  22. float alpha;
  23.  
  24. //used to flip u tex coord to make flag always appear readable to user
  25. float tcMod;
  26.  
  27. //force of wind (from 0 to... something that looks good... around 5-ish)
  28. float windForce;
  29.  
  30. //theta of wave in flag
  31. float waveTheta;
  32.  
  33. //shader input
  34. struct VS_INPUT
  35. {
  36.     float4 Pos : POSITION;
  37.     float4 Normal : NORMAL;
  38.     float2 Tex0 : TEXCOORD0;
  39. };
  40.  
  41. //shader output
  42. struct VS_OUTPUT
  43. {
  44.     float4 Pos : POSITION;
  45.     float4 Color : COLOR;
  46.     float2 Tex0 : TEXCOORD0;
  47. };
  48.  
  49. //shader code
  50. VS_OUTPUT VShader(VS_INPUT In)
  51. {
  52.     VS_OUTPUT Out;
  53.     
  54.     float4 pos=In.Pos;
  55.     float4 norm=In.Normal;
  56.     
  57.     //make droop in low wind
  58.     float droopAmt=abs(2.1-windForce)*0.35f*In.Pos.y;
  59.     pos.z-=droopAmt;
  60.     pos.y-=sqrt(abs((droopAmt)*0.2f))*In.Pos.y*0.5f;
  61.     norm.y-=droopAmt*0.2f*In.Pos.z;
  62.     
  63.     //waves in x axis
  64.     float waveMag=saturate(windForce*0.3)*3.33333f;
  65.     
  66.     float xMove=(sin(In.Pos.y+waveTheta)+cos(In.Pos.z+waveTheta))*0.3f*(waveMag+0.1f);
  67.     pos.x+=xMove*In.Pos.y*(1.0f/7.0f);
  68.     pos.y-=In.Pos.y*waveMag*0.1f;
  69.     norm.y+=3.5f/xMove;
  70.     norm.z+=xMove*0.11f;
  71.     norm.x-=xMove*0.08f;
  72.     
  73.     //waves in z axis
  74.     float zMove=sin(waveTheta+In.Pos.y*2)*waveMag*0.01f*In.Pos.y;
  75.     pos.z+=zMove;
  76.     norm.x-=zMove;
  77.     
  78.     //waves in y axis
  79.     float yMove=sin(waveTheta*0.75f+In.Pos.z*1.5f+1.0f)*waveMag*0.015f*In.Pos.y;
  80.     pos.y+=yMove;
  81.     norm.z-=yMove;
  82.     
  83.     //calc directional light color
  84.     norm.xyz=mul(matWorld,normalize(norm.xyz)); //rotate normal
  85.     
  86.     float3 l1Contrib=dot(-norm.xyz,l1Direction.xyz)*l1Color.xyz;
  87.     l1Contrib=abs(l1Contrib);
  88.     
  89.     float3 l2Contrib=dot(-norm.xyz,l2Direction.xyz)*l2Color.xyz;
  90.     l2Contrib=abs(l2Contrib);
  91.     
  92.     Out.Color.xyz=l1Contrib + l2Contrib + lAmbient.xyz;
  93.     Out.Color.a=alpha; //see through cloth a little
  94.     
  95.     Out.Color.xyz+=(xMove*yMove*zMove)*2.0f;
  96.     
  97.     //calc transformed position and copy texture coord
  98.     pos.xyz*=1.5f; //scaling here.. temp
  99.     Out.Pos=mul(matWorldViewProj,pos);
  100.     Out.Tex0=float2(In.Tex0.x*tcMod,In.Tex0.y);
  101.   
  102.     //spit out the results
  103.     return Out;
  104. }
  105.